var Report = {

    selected_row_id: null,
    objGrid: null,

    init: function () {
        var self = this;

        $("#branch").change(function() {
            var value = $(this).val();
            var select = document.getElementById('teller');
            select.options.length = 0;
            if( typeof branch_tellers[value] == "undefined" ) {
                var opt = document.createElement('option');
                opt.value = 0;
                opt.text = 'All Tellers';
                select.add(opt, null);
                return;
            }
            var d_options = branch_tellers[value];
            //All Tellers
            var opt = document.createElement('option');
            opt.value = 0;
            opt.text = 'All Tellers';
            try { //Standard
                select.add(opt, null);
            }
            catch( error ) { //IE Only
                select.add(opt);
            }
            for(var nx in d_options) {
                var opt = document.createElement('option');
                opt.value = d_options[nx]['id'];
                opt.text = d_options[nx]['fname'] + " " + d_options[nx]['mname']+ " " + d_options[nx]['lname'];
                try { //Standard
                    select.add(opt, null);
                }
                catch( error ) { //IE Only
                    select.add(opt);
                }
            }
            $('#teller').val(selected_teller);
        }).change();

        self.objGrid = $('#flex').flexigrid({
            colModel: [
                {display: 'Date', width: 100,align: 'left'},
                {display: 'Reference', width: 100,align: 'left'},
                {display: 'Branch', width: 100,align: 'left'},
                {display: 'Teller', width: 110, align: 'center'},
                {display: 'Debits GHc', width: 70, align: 'center'},
                {display: 'Reason', width: 250, align: 'center'}
            ],
            height:500,
            subgrid: {
                use: false
            }
        });

        $("#export-btn").click(function () {
            self.print_export_Details('export');
        });
        $("#print-btn").click(function () {
            self.print_export_Details('print');
        });

        $("#start_dt,#end_dt").mask("9999-99-99");
    },

    print_export_Details: function(data_type){
        $("#print-export-form #data_type").val(data_type);
        $("#print-export-form #data_start_dt").val($("#form-query #start_dt").val());
        $("#print-export-form #data_end_dt").val($("#form-query #end_dt").val());
        $("#print-export-form #data_branch").val($("#form-query #branch").val());
        $("#print-export-form #data_teller").val($("#form-query #teller").val());
        window.open('', "PrintExportWindow", "menubar=yes, width=600, height=500,location=no,status=no,scrollbars=yes,resizable=yes");
        $("#print-export-form").submit();
    }
};

/* when the page is loaded */
$(document).ready(function () {
    Report.init();
});